package com.wing.home.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wing.common.utils.JsonResult;
import com.wing.home.entity.*;
import com.wing.home.service.HomeService;
import com.wing.purchase.model.entity.SupplierInfo;
import com.wing.purchase.service.SupplierInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 主页
 *
 * @author xiayang
 */
@Validated
@Api(value = "主页管理", tags = "#/home/home")
@RestController("homeController")
@RequestMapping("home/admin/home")
public class HomeController {

    @Resource
    private HomeService homeService;

    @Resource
    private SupplierInfoService supplierInfoService;

    @ApiOperation(value = "供应商列表", notes = "供应商列表")
    @GetMapping("/supplierList")
    public JsonResult supplierList() {
        QueryWrapper<SupplierInfo> query = new QueryWrapper<>();
        List<SupplierInfo> supplierList = supplierInfoService.list(query);
        return JsonResult.success(supplierList);
    }

    @ApiOperation(value = "采购趋势-按数量", notes = "采购趋势-按数量")
    @GetMapping("/purchaseTrendByNum")
    public JsonResult purchaseTrendByNum(Long supplierId) {
        Map param = new HashMap();
        param.put("supplierId", supplierId);
        List<PurchaseTrendNumber> purchaseTrendNumberList = homeService.purchaseTrendNumTotal(param);
        return JsonResult.success(purchaseTrendNumberList);
    }

    @ApiOperation(value = "采购趋势-按金额", notes = "采购趋势-按金额")
    @GetMapping("/purchaseTrendBySum")
    public JsonResult purchaseTrendBySum(Long supplierId) {
        Map param = new HashMap();
        param.put("supplierId", supplierId);
        List<PurchaseTrendAmount> purchaseTrendAmountList = homeService.purchaseTrendAmountTotal(param);
        return JsonResult.success(purchaseTrendAmountList);
    }

    @ApiOperation(value = "仓库统计", notes = "仓库统计")
    @GetMapping("/warehouseTotal")
    public JsonResult warehouseTotal(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        WarehouseTotal warehouseTotal = homeService.warehouseTotal(param);
        return JsonResult.success(warehouseTotal);
    }

    @ApiOperation(value = "出入库统计", notes = "出入库统计")
    @GetMapping("/inventoryInOutTotal")
    public JsonResult inventoryInOutTotal(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<InventoryInOutNum> inventoryInOutTotalList = homeService.inventoryInOutTotal(param);
        return JsonResult.success(inventoryInOutTotalList);
    }

    @ApiOperation(value = "出库物料排行", notes = "出库物料排行")
    @GetMapping("/outStorageMaterialTop")
    public JsonResult outStorageMaterialTop(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("inventoryType", 2);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<InOutStorageMaterialTop> list = homeService.inOutStorageMaterialTop(param);
        return JsonResult.success(list);
    }

    @ApiOperation(value = "入库物料排行", notes = "入库物料排行")
    @GetMapping("/inStorageMaterialTop")
    public JsonResult inStorageMaterialTop(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("inventoryType", 1);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<InOutStorageMaterialTop> list = homeService.inOutStorageMaterialTop(param);
        return JsonResult.success(list);
    }

    @ApiOperation(value = "出库类型排行", notes = "出库类型排行")
    @GetMapping("/outStorageTypeTop")
    public JsonResult outStorageTypeTop(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("inventoryType", 2);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<InOutStorageTypeTop> list = homeService.inOutStorageTypeTop(param);
        return JsonResult.success(list);
    }

    @ApiOperation(value = "入库类型排行", notes = "入库类型排行")
    @GetMapping("/inStorageTypeTop")
    public JsonResult inStorageTypeTop(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("inventoryType", 1);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<InOutStorageTypeTop> list = homeService.inOutStorageTypeTop(param);
        return JsonResult.success(list);
    }

    @ApiOperation(value = "物料类别统计", notes = "物料类别统计")
    @GetMapping("/productTypeTotal")
    public JsonResult productTypeTotal(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<ProductTypeTotal> list = homeService.productTypeTotal(param);
        return JsonResult.success(list);
    }

    @ApiOperation(value = "仓库类型统计", notes = "仓库类型统计")
    @GetMapping("/warehouseTypeTotal")
    public JsonResult warehouseTypeTotal(Long warehouseId, Integer queryType, String startTime, String endTime) {
        Map param = new HashMap();
        param.put("warehouseId", warehouseId);
        param.put("queryType", queryType);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        List<WarehouseTypeTotal> list = homeService.warehouseTypeTotal(param);
        return JsonResult.success(list);
    }

}
